export class Rect {
  constructor (x, y, width, height, mouse, cxt) {
    this._x = x
    this._y = y
    this._width = width
    this._height = height
    this._mouse = mouse
    this._cxt = cxt
    this._color = null
    this._index = 0
  }

  checkMouse () {
    let check = this._mouse.x > this._x &&
        this._mouse.x < this._x + this._width &&
        this._mouse.y > this._y &&
        this._mouse.y < this._y + this._height
    return check
  }
  get color () {
    return this._color
  }
  set color (color) {
    this._color = color
  }
  resetIndex () {
    this._index = 0
  }
  fill (color) {
    if (this._index === 0) {
      this._color = color
      this._cxt.fillStyle = color
      this._cxt.fillRect(this._x * this._width, this._y * this._width, this._width, this._height)
      this._index = 1
    }
  }
}
